home *** CD-ROM | disk | FTP | other *** search
/ Programming an RTS Game with Direct3D / Programming an RTS Game with Direct3D.iso / Examples / Chapter 5 / Example 5.5 / camera.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  2006-06-29  |  719 b   |  36 lines

  1. #include "camera.h"
  2.  
  3. CAMERA::CAMERA()
  4. {
  5.     Init(NULL);
  6. }
  7.  
  8. void CAMERA::Init(IDirect3DDevice9* Dev)
  9. {
  10.     m_pDevice = Dev;
  11.     m_fov = D3DX_PI / 4.0f;
  12.     m_eye = D3DXVECTOR3(50.0f, 50.0f, 50.0f);
  13.     m_focus = D3DXVECTOR3(0.0f, 0.0f, 0.0f);
  14. }
  15.  
  16. D3DXMATRIX CAMERA::GetViewMatrix()
  17. {
  18.     D3DXMATRIX  matView;
  19.     D3DXMatrixLookAtLH(&matView, &m_eye, &m_focus, &D3DXVECTOR3(0.0f, 1.0f, 0.0f));
  20.  
  21.     return  matView;
  22. }
  23.  
  24. D3DXMATRIX CAMERA::GetProjectionMatrix()
  25. {
  26.     D3DXMATRIX  matProj;
  27.     D3DVIEWPORT9 v;
  28.     m_pDevice->GetViewport(&v);
  29.  
  30.     float aspect = v.Width / v.Height;
  31.     if(v.Height > v.Width)
  32.         aspect = v.Height / v.Width;
  33.  
  34.     D3DXMatrixPerspectiveFovLH(&matProj, m_fov, aspect, 0.1f, 1000.0f );
  35.     return matProj;
  36. }